package com.cheboohui.iqs.deal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.common.basic.StringUtil;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.config.PrivateTool;
import com.cheboohui.iqs.controller.BaseController;

/**
 * 自定义接口处理
 * 
 * @author xielonghai
 *
 */
public class CustomizeDeal {

	public static String backUrl = "http://113.204.21.26/pay/union/toPay";

	/**
	 * logger:日志工具.
	 */
	private static Log log = LogFactory.getLog(CustomizeDeal.class);

	/**
	 * 自定义接口处理
	 * 
	 * @param request
	 * @param response
	 */
	public static void customize(HttpServletRequest request, HttpServletResponse response) {
		log.info("进入" + Config.value + ",自定义处理接口....");
		try {
			JSONObject param = PrivateTool.paramtenToJson(request.getParameterMap());
			if (null == param) {
				BaseController.setResponseText(response, "请求参数获取转化异常");
				return;
			}

			log.info(Config.value + ",自定义处理接口请求参数:" + param);
			if ("set".equals(param.getString("type"))) {
				if (!StringUtil.isNulls(param.getString("backUrl")))
					backUrl = param.getString("backUrl");
				BaseController.setResponseText(response, backUrl);
				return;
			}

			BaseController.setResponseText(response, "暂时该接口未启用");
		} catch (Exception e) {
			log.error(Config.value + ",自定义处理接口实现异常:" + e);
			BaseController.setResponseText(response, "自定义处理接口实现异常:" + e.getMessage());
		}
	}
}
